<?php
/**
 * Created by PhpStorm.
 * Author: ljz
 * Date: 2023/5/06
 * Time: 14:34
 */

namespace App\store\models;


use App\common\models\BaseModel;
use Illuminate\Support\Facades\DB;

/**
 * Class OrderModel
 * @package app\common\models
 */
class ShopModel extends BaseModel
{
    const table = 'store';
    public $attributes = ['display_order' => 0];

    public function __construct() {

    }

    /**
     * 查询字段规则
     *
     * @return array
     */
    static public function rules()
    {
        return [
            'store_id' => 'required|int',
        ];
    }

    /**
     * 更新字段规则
     *
     * @return array
     */
    static public function update_rules()
    {
        return [
            'store_id' => 'required|int',
            'store_name' => 'required|string|max:255',
            'logo_thumb' => 'required|string|max:255',
            'banner_thumb' => 'required|string|max:255',
            'business_hours_start' => 'required|string|max:255',
            'business_hours_end' => 'required|string|max:255',
            'store_introduce' => 'required|string|max:255',
            'location' => 'required|string|max:255',
        ];
    }

    /**
     * 字段验证返回错误信息
     *
     * @return array
     */
    static public function message()
    {
        return [
            'store_id.required' => '商户ID不能为空',
            'store_id.int' => '商户ID不是纯数字',
            'store_name.required' => '商户名称不能为空',
            'store_name.max' => '商户名称不能超过最大限制数',
            'logo_thumb.required' => '店铺logo不能为空',
            'banner_thumb.required' => '门店banner不能为空',
            'business_hours_start.required' => '营业开始时间不能为空',
            'business_hours_end.required' => '营业结束时间不能为空',
            'store_introduce.required' => '门店介绍不能为空',
            'location.required' => '定位不能为空',
        ];
    }

    /**
     * 数据库 - 查询详情
     * @param $data //参数数组
     * @return array
     */
    static public function detailsed($data)
    {
        $data = DB::table(self::table)
            ->select('store_name', 'logo_thumb', 'banner_thumb', 'business_hours_start', 'business_hours_end', 'store_introduce', 'location')
            ->where('id','=', $data['store_id'])
            ->first();

        return $data;
    }

    /**
     * 数据库 - 查询详情
     * @param $id //店铺ID
     * @param $data //参数数组
     * @return array
     */
    static public function updatedData($id, $data)
    {
        $data = DB::table(self::table)
            ->where('id','=', $id)
            ->update($data);

        return $data;
    }

}
